﻿package com.wandian.view.components.ui
{
	import com.wandian.data.GameData;

	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	/**
	 * 倒计时管理
	 * mcFl,闪动特效
	 * mcNum,计时
	 * @author long
	 * @QQ 108232706
	 * @version 1.0
	 */
	public class TimerManage extends Object
	{
		private var _mcFl:MovieClip;
		private var _mcNum:MovieClip;
		private var _timer:Timer;
		private var _global:GameData;
		private var _isFrist:Boolean=true;

		public function TimerManage(mcFl:MovieClip, mcNum:MovieClip)
		{
			this._global=GameData.getInstance();
			this._mcFl=mcFl;
			this._mcNum=mcNum;
			this._mcFl.gotoAndStop(1);
			this._mcNum.visible=false;
			this._timer=new Timer(1000, GameData._objRoom.bettime);
			this._timer.addEventListener(TimerEvent.TIMER, this.changeTimer);
			this.hideTimer();
			return;
		}

		private function changeTimer(event:Event):void
		{
			if (GameData._objRoom == null)
			{
				return;
			}
			if (this._timer != null)
			{
				var currentTime:int=GameData._objRoom.bettime - this._timer.currentCount;
				this._mcNum.gotoAndStop(currentTime);
				if (GameData._nCurSeatId == this._global.seatId)
				{
					if (this._isFrist)
					{
						if (GameData._nCurSeatId != 0)
						{
							if (currentTime <= 10)
							{
								this._isFrist=false;
								SoundManage.playSound("PlayerSecondTen");
							}
						}
					}
				}


			}

			return;
		}

		public function showTimer():void
		{
			this._isFrist=true;
			this._mcFl.visible=true;
			this._mcNum.visible=true;
			if (this._timer != null)
			{
				this._timer.reset();
				this._timer.start();
			}
			this._mcNum.gotoAndStop(GameData._objRoom.bettime);
			this._mcFl.gotoAndPlay(2);
			return;
		}

		public function hideTimer():void
		{
			SoundManage.playSound("StopSecondTen");
			if (this._timer != null)
			{
				this._timer.reset();
			}
			this._mcFl.visible=false;
			this._mcNum.visible=false;
			this._mcFl.gotoAndStop(1);
			this._mcNum.gotoAndStop(1);
			return;
		}

		public function removeThis():void
		{
			if (this._timer != null)
			{
				this.hideTimer();
				this._timer.removeEventListener(TimerEvent.TIMER, this.changeTimer);
				this._timer=null;
			}
			return;
		}

	}
}
